import { createWebHashHistory, createRouter, RouteRecordRaw } from 'vue-router';

import Layout from '@renderer/layout/index.vue';


export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    component: () => import('@renderer/view/login/index.vue'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import("@renderer/view/index/index.vue"),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]

  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@renderer/view/profile/index.vue'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  }


]

export const dynamicRoutes: RouteRecordRaw[] = [

];

/**
 * 创建路由
 */
const router = createRouter({
  mode: 'hash',
  history: createWebHashHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  }
});

export default router;
